﻿using System;
using System.Globalization;
using System.Xml.Serialization;

namespace ICalendar.CalendarProperties
{
    [Serializable]
    [XmlRoot("categories")]  
    public class Categories : CalendarPropertyBase<string[]>
    {
        public CultureInfo Language { get; set; }

        protected override void SetValue(string value)
        {
            this.Value = value.Split(',');
        }

        protected override string GetValue()
        {
            return string.Join(",", this.Value);
        }

        protected override void SetParametersFromXParameters(XParameterCollection xparams)
        {
            if (xparams == null)
                return;

            var language = xparams.GetValue(ReservedNames.ParameterLanguage);
            if (language != null)
            {
                this.Language = CultureInfo.GetCultureInfo(language);
            }
        }

        protected override XParameterCollection GetXParametersFromParameters()
        {
            return new XParameterCollection
                       {
                           {ReservedNames.ParameterLanguage, Language.Name}
                       };
        }


        protected override string[] GetXReservedParametersNames()
        {
            return new[] { ReservedNames.ParameterLanguage};
        }
    }
}
